##############################################################################
# CMake
##############################################################################

cmake_minimum_required(VERSION 2.8.0)
project(gui)

# 添加下面一行，避免找不到 ui_main_window.hpp 头文件错误。
SET(CMAKE_INCLUDE_CURRENT_DIR ON)

add_compile_options(-std=c++11)
##############################################################################
# Catkin
##############################################################################

# qt_build provides the qt cmake glue, roscpp the comms for a default talker
find_package(catkin REQUIRED COMPONENTS
    std_msgs
    roscpp
    agv_msgs
)

find_package(Qt5 REQUIRED Core Widgets Network)
set(QT_LIBRARIES Qt5::Widgets Qt5::Network)

include_directories(include/agv_msgs)
include_directories(${catkin_INCLUDE_DIRS})

find_package(OpenCV 3 REQUIRED)
include_directories(${OpenCV_INCLUDES})

find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDES})

link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib)

# Use this to define what the package will export (e.g. libs, headers).
# Since the default here is to produce only a binary, we don't worry about
# exporting anything. 
catkin_package(
    INCLUDE_DIRS include
)

##############################################################################
# Qt Environment
##############################################################################

# this comes from qt_build's qt-ros.cmake which is automatically 
# included via the dependency call in package.xml
#rosbuild_prepare_qt4(QtCore QtGui) # Add the appropriate components to the component list here

##############################################################################
# Sections
##############################################################################

file(GLOB QT_FORMS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ui/*.ui)
file(GLOB QT_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} resources/*.qrc)
file(GLOB_RECURSE QT_MOC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS include/gui/*.h*)

#QT4_ADD_RESOURCES(QT_RESOURCES_CPP ${QT_RESOURCES})
#QT4_WRAP_UI(QT_FORMS_HPP ${QT_FORMS})
#QT4_WRAP_CPP(QT_MOC_HPP ${QT_MOC})

QT5_ADD_RESOURCES(QT_RESOURCES_CPP ${QT_RESOURCES})
QT5_WRAP_UI(QT_FORMS_HPP ${QT_FORMS})
QT5_WRAP_CPP(QT_MOC_HPP ${QT_MOC})

##############################################################################
# Sources
##############################################################################

file(GLOB_RECURSE QT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS src/*.cpp)

##############################################################################
# Binaries
##############################################################################

add_executable(gui ${QT_SOURCES} ${QT_RESOURCES_CPP} ${QT_FORMS_HPP} ${QT_MOC_HPP} )
target_link_libraries(
    ${PROJECT_NAME}
    ${QT_LIBRARIES}
    ${catkin_LIBRARIES}
    ${OpenCV_LIBS}
    bx_sdkDual
    iconv
)


install(TARGETS gui RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} )

install(DIRECTORY para pic Fonts lib
  DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
  USE_SOURCE_PERMISSIONS
)

install(FILES
   lib/libbx_sdkDual.so
   lib/libbx_sdkDual.so.1
   lib/libbx_sdkDual.so.1.0
   lib/libbx_sdkDual.so.1.0.0
   lib/libcharset.so
   lib/libcharset.so.1
   lib/libcharset.so.1.0.0
   lib/libiconv.so
   lib/libiconv.so.2
   lib/libiconv.so.2.6.0
   lib/preloadable_libiconv.so
   DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})
